package zhoug.common.adapters;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

/**
 * 描述：FragmentPagerAdapter 基类
 * zhougan
 * 2020/3/5
 **/
public class BaseFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
    private List<? extends Fragment> pages;
    private List<String> titles;
    private boolean itemPositionNone =false;

    public BaseFragmentStatePagerAdapter(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
    }

    public BaseFragmentStatePagerAdapter(FragmentManager fm) {
        super(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    public List<? extends Fragment> getPages() {
        return pages;
    }

    public void setPages(List<? extends Fragment> pages) {
        this.pages = pages;
    }

    public List<String> getTitles() {
        return titles;
    }

    public void setTitles(List<String> titles) {
        this.titles = titles;
    }



    @Override
    public Fragment getItem(int i) {
        if(pages!=null){
            return pages.get(i);
        }
        return null;
    }

    @Override
    public int getCount() {
        if(pages!=null){
            return pages.size();
        }
        return 0;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if(titles!=null){
            return titles.get(position);
        }
        return null;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        if(itemPositionNone){
            return POSITION_NONE;
        }
        return super.getItemPosition(object);
    }

    public void setItemPositionNone(boolean itemPositionNone) {
        this.itemPositionNone = itemPositionNone;
    }

}